#include "main.h"
#include <stdio.h>
#include <stdlib.h>

extern SPI_HandleTypeDef hspi1;

/* printf the device id of the dw1000 ,testing the spi with dw1000  */
/* set the function after dw1000 init and reset */

void dw1000_read_device_id(void)
{
	HAL_StatusTypeDef status;
	uint8_t header = 0x00;
	uint32_t device_id;

	
	HAL_GPIO_WritePin(UWB_CSN_GPIO_Port, UWB_CSN_Pin, GPIO_PIN_RESET);
	
	status = HAL_SPI_Transmit(&hspi1,&header, 1, 1000);
	if (status != HAL_OK) {
		printf("send header fail, err is %d\r\n", status);
	}
	
	status = HAL_SPI_Receive(&hspi1, (uint8_t *)&device_id, 4, 500);
	if (status != HAL_OK) {
		printf("read device id fail, err is %d\r\n", status);
	}

	if (device_id != 0) {
		printf("device id is 0x%8x\r\n", device_id);
	} else {
		printf("device id read fail\r\n");
	}
	
}